﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB.Mechanical;
using YArchitech.HCLoad.Utils;

namespace YArchitech.HCLoad.Export
{
	public class HcSpaceDataFilter
	{
		public int FilterOptions
		{
			get
			{
				return this.m_nFilterOptions;
			}
			set
			{
				this.m_nFilterOptions = value;
			}
		}

		public StringFilterType NameFilterType
		{
			get
			{
				return this.m_eNameFilterType;
			}
			set
			{
				this.m_eNameFilterType = value;
			}
		}

		public string Name
		{
			get
			{
				return this.m_sName;
			}
			set
			{
				this.m_sName = value;
			}
		}

		public RangeFilterType AreaFilterType
		{
			get
			{
				return this.m_eAreaFilterType;
			}
			set
			{
				this.m_eAreaFilterType = value;
			}
		}

		public HcValueRange AreaRange
		{
			get
			{
				return this.m_areaRange;
			}
			set
			{
				this.m_areaRange = value;
			}
		}

		public List<Space> GetSpaces(List<Space> Spaces)
		{
			int num = 1 << Convert.ToInt32(EnumFilterChecker.eName);
			int num2 = 1 << Convert.ToInt32(EnumFilterChecker.eArea);
			int num3 = 1 << Convert.ToInt32(EnumFilterChecker.eNumber);
			bool bCheck = num == (num & this.m_nFilterOptions);
			bool bCheck2 = num2 == (num2 & this.m_nFilterOptions);
			bool bCheck3 = num3 == (num3 & this.m_nFilterOptions);
			List<Space> list = new List<Space>();
			foreach (Space space in Spaces)
			{
				if (space != null && this.CheckName(bCheck, space) && this.CheckArea(bCheck2, space) && this.CheckNumber(bCheck3, space))
				{
					list.Add(space);
				}
			}
			return list;
		}

		public bool CheckArea(bool bCheck, Space space)
		{
			return !bCheck || this.m_areaRange.InRange(space.Area);
		}

		public bool CheckNumber(bool bCheck, Space space)
		{
			return true;
		}

		public bool CheckName(bool bCheck, Space space)
		{
			if (!bCheck)
			{
				return true;
			}
			string name = space.Name;
			name.ToUpper();
			string sName = this.m_sName;
			sName.ToUpper();
			bool result = true;
			switch (this.m_eNameFilterType)
			{
			case StringFilterType.eEqual:
				result = name.Equals(sName);
				break;
			case StringFilterType.eInclude:
				result = name.Contains(sName);
				break;
			case StringFilterType.eExclude:
				result = !name.Contains(sName);
				break;
			}
			return result;
		}

		private int m_nFilterOptions;

		private StringFilterType m_eNameFilterType;

		private string m_sName;

		private RangeFilterType m_eAreaFilterType;

		private HcValueRange m_areaRange;
	}
}
